package com.ruoyi.custom.service.impl;

import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.custom.mapper.AcademyTrackingMapper;
import com.ruoyi.custom.domain.AcademyTracking;
import com.ruoyi.custom.service.IAcademyTrackingService;

/**
 * 学员跟踪Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-03-27
 */
@Service
public class AcademyTrackingServiceImpl implements IAcademyTrackingService 
{
    @Autowired
    private AcademyTrackingMapper academyTrackingMapper;

    /**
     * 查询学员跟踪
     * 
     * @param id 学员跟踪主键
     * @return 学员跟踪
     */
    @Override
    public AcademyTracking selectAcademyTrackingById(Long id)
    {
        return academyTrackingMapper.selectAcademyTrackingById(id);
    }

    /**
     * 查询学员跟踪列表
     * 
     * @param academyTracking 学员跟踪
     * @return 学员跟踪
     */
    @Override
    public List<AcademyTracking> selectAcademyTrackingList(AcademyTracking academyTracking)
    {
        return academyTrackingMapper.selectAcademyTrackingList(academyTracking);
    }

    /**
     * 新增学员跟踪
     * 
     * @param academyTracking 学员跟踪
     * @return 结果
     */
    @Override
    public int insertAcademyTracking(AcademyTracking academyTracking)
    {
        return academyTrackingMapper.insertAcademyTracking(academyTracking);
    }

    /**
     * 修改学员跟踪
     * 
     * @param academyTracking 学员跟踪
     * @return 结果
     */
    @Override
    public int updateAcademyTracking(AcademyTracking academyTracking)
    {
        return academyTrackingMapper.updateAcademyTracking(academyTracking);
    }

    /**
     * 批量删除学员跟踪
     * 
     * @param ids 需要删除的学员跟踪主键
     * @return 结果
     */
    @Override
    public int deleteAcademyTrackingByIds(Long[] ids)
    {
        return academyTrackingMapper.deleteAcademyTrackingByIds(ids);
    }

    /**
     * 删除学员跟踪信息
     * 
     * @param id 学员跟踪主键
     * @return 结果
     */
    @Override
    public int deleteAcademyTrackingById(Long id)
    {
        return academyTrackingMapper.deleteAcademyTrackingById(id);
    }

    @Override
    public void following(AcademyTracking academyTracking) {
        Long id = academyTracking.getId();
        AcademyTracking academyTracking2 = academyTrackingMapper.selectAcademyTrackingById(id);
        if (academyTracking2 !=null){
            BeanUtil.copyProperties(academyTracking,academyTracking2);
            academyTracking2.setTrackingTimes(academyTracking2.getTrackingTimes()+1);
            academyTrackingMapper.updateAcademyTracking(academyTracking2);
        }
    }
}
